`
https://leetcode.cn/problems/product-of-array-except-self/
`

/**
 * @param {number[]} nums
 * @return {number[]}
 */
var productExceptSelf = function (nums) {
  const n = nums.length
  // 前缀积
  const prefix = new Array(n)
  prefix[0] = nums[0]
  for (let i = 1; i < n; i++) {
    prefix[i] = prefix[i - 1] * nums[i]
  }
  // 后缀积
  const suffix = new Array(n)
  suffix[n - 1] = nums[n - 1]
  for (let i = n - 2; i >= 0; i--) {
    suffix[i] = suffix[i + 1] * nums[i]
  }
  // 结果
  const res = new Array(n)
  res[0] = suffix[1]
  res[n - 1] = prefix[n - 2]
  for (let i = 1; i < n - 1; i++) {
    res[i] = prefix[i - 1] * suffix[i + 1]
  }
  return res
};